import { Component, OnInit } from '@angular/core';
import { HttpClient } from "@angular/common/http"
import { Router } from "@angular/router"

@Component({
  selector: 'app-navbar',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {

  user = JSON.parse(window.localStorage.getItem('user_info') || '{}')

  constructor(
    private http: HttpClient,
    private router: Router
  ) { }

  siginout() {
    this.http.delete("http://localhost:3000/session").toPromise().then(data=>{
      window.localStorage.removeItem('auth_token')
      this.router.navigate(['/sigin']) //跳转到登录页面
    }).catch(err=>{
      console.log('退出失败！')
    })
  }

  ngOnInit() {
  }

}
